﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using MaxStudio.Concrete.Web;
using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server;
using MaxStudio.Concrete.Server.Service;
using MaxStudio.Concrete.Server.Dao;
using System.Configuration;

namespace MaxStudio.Concrete.Web.Pages
{
    public partial class RPTOpeningAppraisal : BasePage
    {
        string wholSequence = "LT/S实-12";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindGridView();
            }
        }
        #region Private Method

        private void BindGridView()
        {
            RPTOpeningAppraisalService RPTOpeningAppraisalServiceObj = ServiceFactory.getRPTOpeningAppraisalService();
            OperationResult<List<tb_RPT_OpeningAppraisal>> result = RPTOpeningAppraisalServiceObj.GetAllOpeningAppraisal();

            if (result.operationSuccess)
            {
                gvRPTOpeningAppraisalList.DataSource = result.obj;
                gvRPTOpeningAppraisalList.DataBind();
            }
            else
            {
                //EXCEPTION
                //return null;
            }
        }

        private void BindEdieDialog(int id)
        {
            RPTOpeningAppraisalService RPTOpeningAppraisalServiceObj = ServiceFactory.getRPTOpeningAppraisalService();
            OperationResult<tb_RPT_OpeningAppraisal> resultEdit = RPTOpeningAppraisalServiceObj.GetOpeningAppraisalById(id);


            if (resultEdit.operationSuccess == true)
            {
                txtEditReportSequence.Text = resultEdit.obj.ReportSequence;
                txtEditIDSequence.Text = resultEdit.obj.IDSequence;
                txtEditMixingEquipment.Text = resultEdit.obj.MixingEquipment;
                txtEditProjectName.Text = resultEdit.obj.ProjectName;
                txtEditConstructionUnit.Text = resultEdit.obj.ConstructionUnit;
                txtEditStrengthGrade.Text = resultEdit.obj.StrengthGrade;
                txtEditMixNumbers.Text = resultEdit.obj.MixNumbers;
                txtEditASHThan.Text = resultEdit.obj.ASHThan;
                txtEditDemandslump.Text = resultEdit.obj.Demandslump;
                txtEditTestunit.Text = resultEdit.obj.Testunit;
                txtEditSandRatio.Text = resultEdit.obj.SandRatio;
                txtEditWaterCement1.Text = resultEdit.obj.WaterCement1;
                txtEditFine1.Text = resultEdit.obj.Fine1;
                txtEditCoarseSand1.Text = resultEdit.obj.CoarseSand1;
                txtEditStones1.Text = resultEdit.obj.Stones1;
                txtEditWater1.Text = resultEdit.obj.Water1;
                txtEditAdmixture1.Text = resultEdit.obj.Admixture1;
                txtEditASH1.Text = resultEdit.obj.ASH1;
                txtEditExpansionAgent1.Text = resultEdit.obj.ExpansionAgent1;
                txtEditFineSandWater.Text = resultEdit.obj.FineSandWater;
                txtEditCoarseSandWater.Text = resultEdit.obj.CoarseSandWater;
                txtEditWaterCement2.Text = resultEdit.obj.WaterCement2;
                txtEditFine2.Text = resultEdit.obj.Fine2;
                txtEditCoarseSand2.Text = resultEdit.obj.CoarseSand2;
                txtEditStones2.Text = resultEdit.obj.Stones2;
                txtEditWater2.Text = resultEdit.obj.Water2;
                txtEditAdmixture2.Text = resultEdit.obj.Admixture2;
                txtEditASH2.Text = resultEdit.obj.ASH2;
                txtEditExpansionAgent2.Text = resultEdit.obj.ExpansionAgent2;
                txtEditDESIGNDegreeSlump.Text = resultEdit.obj.DESIGNDegreeSlump;
                txtEditDESIGNSpread.Text = resultEdit.obj.DESIGNSpread;
                txtEditDESIGNCompressiveStrength.Text = resultEdit.obj.DESIGNCompressiveStrength;
                txtEditMEASUSDegreeSlump.Text = resultEdit.obj.MEASUSDegreeSlump;
                txtEditMEASUSSpread.Text = resultEdit.obj.MEASUSSpread;
                txtEditMEASUSCompressiveStrength.Text = resultEdit.obj.MEASUSCompressiveStrength;
                txtEditIsSameAsApply.Text = resultEdit.obj.IsSameAsApply;
                txtEditREMARKDegreeSlump.Text = resultEdit.obj.REMARKDegreeSlump;
                txtEditREMARKSpread.Text = resultEdit.obj.REMARKSpread;
                txtEditREMARKCompressiveStrength.Text = resultEdit.obj.REMARKCompressiveStrength;
                txtEditRemark.Text = resultEdit.obj.Remark;
                txtEditBuildUnit.Text = resultEdit.obj.BuildUnit;
                txtEditConcreteTestMatchUnit.Text = resultEdit.obj.ConcreteTestMatchUnit;
                txtEditUnitHeadTechnology.Text = resultEdit.obj.UnitHeadTechnology;
                txtEditMixingUnit.Text = resultEdit.obj.MixingUnit;
                txtEditTestDate.Text = resultEdit.obj.TestDate;

                lbLastModier.Text = "TEST";
                lbEidtId.Text = resultEdit.obj.Id.ToString();
                lbLastModifyDate.Text = resultEdit.obj.ModifyDate.ToShortDateString();
            }
        }

        private void DeleteRecords(int id)
        {
            lbDeleteId.Text = id.ToString();
        }

        #endregion

        #region Event

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            RPTOpeningAppraisalService RPTOpeningAppraisalServiceObj = ServiceFactory.getRPTOpeningAppraisalService();
            tb_RPT_OpeningAppraisal instance = new tb_RPT_OpeningAppraisal();

            instance.Sequence = wholSequence;   
            instance.ReportSequence = txtReportSequence.Text;
            instance.IDSequence = txtIDSequence.Text;
            instance.MixingEquipment = txtMixingEquipment.Text;
            instance.ProjectName = txtProjectName.Text;
            instance.ConstructionUnit = txtConstructionUnit.Text;
            instance.StrengthGrade = txtStrengthGrade.Text;
            instance.MixNumbers = txtMixNumbers.Text;
            instance.ASHThan = txtASHThan.Text;
            instance.Demandslump = txtDemandslump.Text;
            instance.Testunit = txtTestunit.Text;
            instance.SandRatio = txtSandRatio.Text;
            instance.WaterCement1 = txtWaterCement1.Text;
            instance.Fine1 = txtFine1.Text;
            instance.CoarseSand1 = txtCoarseSand1.Text;
            instance.Stones1 = txtStones1.Text;
            instance.Water1 = txtWater1.Text;
            instance.Admixture1 = txtAdmixture1.Text;
            instance.ASH1 = txtASH1.Text;
            instance.ExpansionAgent1 = txtExpansionAgent1.Text;
            instance.FineSandWater = txtFineSandWater.Text;
            instance.CoarseSandWater = txtCoarseSandWater.Text;
            instance.WaterCement2 = txtWaterCement2.Text;
            instance.Fine2 = txtFine2.Text;
            instance.CoarseSand2 = txtCoarseSand2.Text;
            instance.Stones2 = txtStones2.Text;
            instance.Water2 = txtWater2.Text;
            instance.Admixture2 = txtAdmixture2.Text;
            instance.ASH2 = txtASH2.Text;
            instance.ExpansionAgent2 = txtExpansionAgent2.Text;
            instance.DESIGNDegreeSlump = txtDESIGNDegreeSlump.Text;
            instance.DESIGNSpread = txtDESIGNSpread.Text;
            instance.DESIGNCompressiveStrength = txtDESIGNCompressiveStrength.Text;
            instance.MEASUSDegreeSlump = txtMEASUSDegreeSlump.Text;
            instance.MEASUSSpread = txtMEASUSSpread.Text;
            instance.MEASUSCompressiveStrength = txtMEASUSCompressiveStrength.Text;
            instance.IsSameAsApply = txtIsSameAsApply.Text;
            instance.REMARKDegreeSlump = txtREMARKDegreeSlump.Text;
            instance.REMARKSpread = txtREMARKSpread.Text;
            instance.REMARKCompressiveStrength = txtREMARKCompressiveStrength.Text;
            instance.Remark = txtRemark.Text;
            instance.BuildUnit = txtBuildUnit.Text;
            instance.ConcreteTestMatchUnit = txtConcreteTestMatchUnit.Text;
            instance.UnitHeadTechnology = txtUnitHeadTechnology.Text;
            instance.MixingUnit = txtMixingUnit.Text;
            instance.TestDate = txtTestDate.Text;



            OperationResult<tb_RPT_OpeningAppraisal> result = RPTOpeningAppraisalServiceObj.CreateOpeningAppraisal (instance);
            BindGridView();

        }
        protected void btnEdit_Click(object sender, EventArgs e)
        {
            int editId = 0;
            if (lbEidtId.Text.Length > 0)
            {
                editId = Int32.Parse(lbEidtId.Text);
            }

            RPTOpeningAppraisalService RPTOpeningAppraisalServiceObj = ServiceFactory.getRPTOpeningAppraisalService();
            tb_RPT_OpeningAppraisal entity = new tb_RPT_OpeningAppraisal();
 
            entity.Id = editId;
            entity.Sequence = wholSequence;
            entity.ReportSequence = txtEditReportSequence.Text;
            entity.IDSequence = txtEditIDSequence.Text;
            entity.MixingEquipment = txtEditMixingEquipment.Text;
            entity.ProjectName = txtEditProjectName.Text;
            entity.ConstructionUnit = txtEditConstructionUnit.Text;
            entity.StrengthGrade = txtEditStrengthGrade.Text;
            entity.MixNumbers = txtEditMixNumbers.Text;
            entity.ASHThan = txtEditASHThan.Text;
            entity.Demandslump = txtEditDemandslump.Text;
            entity.Testunit = txtEditTestunit.Text;
            entity.SandRatio = txtEditSandRatio.Text;
            entity.WaterCement1 = txtEditWaterCement1.Text;
            entity.Fine1 = txtEditFine1.Text;
            entity.CoarseSand1 = txtEditCoarseSand1.Text;
            entity.Stones1 = txtEditStones1.Text;
            entity.Water1 = txtEditWater1.Text;
            entity.Admixture1 = txtEditAdmixture1.Text;
            entity.ASH1 = txtEditASH1.Text;
            entity.ExpansionAgent1 = txtEditExpansionAgent1.Text;
            entity.FineSandWater = txtEditFineSandWater.Text;
            entity.CoarseSandWater = txtEditCoarseSandWater.Text;
            entity.WaterCement2 = txtEditWaterCement2.Text;
            entity.Fine2 = txtEditFine2.Text;
            entity.CoarseSand2 = txtEditCoarseSand2.Text;
            entity.Stones2 = txtEditStones2.Text;
            entity.Water2 = txtEditWater2.Text;
            entity.Admixture2 = txtEditAdmixture2.Text;
            entity.ASH2 = txtEditASH2.Text;
            entity.ExpansionAgent2 = txtEditExpansionAgent2.Text;
            entity.DESIGNDegreeSlump = txtEditDESIGNDegreeSlump.Text;
            entity.DESIGNSpread = txtEditDESIGNSpread.Text;
            entity.DESIGNCompressiveStrength = txtEditDESIGNCompressiveStrength.Text;
            entity.MEASUSDegreeSlump = txtEditMEASUSDegreeSlump.Text;
            entity.MEASUSSpread = txtEditMEASUSSpread.Text;
            entity.MEASUSCompressiveStrength = txtEditMEASUSCompressiveStrength.Text;
            entity.IsSameAsApply = txtEditIsSameAsApply.Text;
            entity.REMARKDegreeSlump = txtEditREMARKDegreeSlump.Text;
            entity.REMARKSpread = txtEditREMARKSpread.Text;
            entity.REMARKCompressiveStrength = txtEditREMARKCompressiveStrength.Text;
            entity.Remark = txtEditRemark.Text;
            entity.BuildUnit = txtEditBuildUnit.Text;
            entity.ConcreteTestMatchUnit = txtEditConcreteTestMatchUnit.Text;
            entity.UnitHeadTechnology = txtEditUnitHeadTechnology.Text;
            entity.MixingUnit = txtEditMixingUnit.Text;
            entity.TestDate = txtEditTestDate.Text;

            entity.ModifyDate = DateTime.Now;
            entity.ModifyBy = 1;
            entity.CreateDate = DateTime.Now;

            OperationResult<tb_RPT_OpeningAppraisal> resultEdit = RPTOpeningAppraisalServiceObj.ModifyOpeningAppraisal(entity);

            BindGridView();
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int deleteId = Int32.Parse(lbDeleteId.Text);
            RPTOpeningAppraisalService RPTOpeningAppraisalServiceObj = ServiceFactory.getRPTOpeningAppraisalService();
            tb_RPT_OpeningAppraisal deleteEntity = new tb_RPT_OpeningAppraisal();

            deleteEntity.Id = deleteId;
            RPTOpeningAppraisalServiceObj.DeleteOpeningAppraisal(deleteEntity);

            BindGridView();
        }

        protected void gvRPTOpeningAppraisalList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
                string strSelectId = e.CommandArgument.ToString();
                BindEdieDialog(Int32.Parse(strSelectId));
            }

            if (e.CommandName == "del")
            {
                string strSelectId = e.CommandArgument.ToString();
                DeleteRecords(Int32.Parse(strSelectId));
            }
        }

        protected void gvRPTOpeningAppraisalList_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvRPTOpeningAppraisalList.PageIndex = e.NewPageIndex;
            BindGridView();
        }
        #endregion
    }
}
